package cn.edu.neusoft.service.car;

import cn.edu.neusoft.config.OauthConfigUtil;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CarIOHandler {
    @Autowired
    private OauthConfigUtil oauthConfigUtil;
    public CarIOResponse getCarIOInfoByTime(CarIORequest carIORequest) {
        OauthConfigUserPwdInfo config = oauthConfigUtil.getOauthConfig();
        CarIOResponse response=null;

        try {
            log.info("CarIOHandler,getCarIOInfoByTime,request:{}", JSONUtil.toJsonStr(carIORequest));
            response = HttpUtils.executeJson("/evo-apigw/ipms/carcapture/find/conditions" + carIORequest.toQueryString()  ,null,null, Method.GET , config, CarIOResponse.class);
//            log.info("CarIOHandler,getCarIOInfoByTime,response:{}", JSONUtil.toJsonStr(response));
        } catch (ClientException e) {
            log.error(e.getErrMsg(), e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(!response.isSuccess()) {
            log.info("获取进出车辆信息失败:{}.{}",response.getErrMsg());
        }
        return response;
    }
}